package com.fansea.job;

import com.fansea.util.HttpRequestUtil;
import com.fansea.util.LoverWordUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

@Component
public class EveryDayTalk {

    @Value("${user.qq}")
    public String userQQ;

    @Scheduled(cron = "0 0 8 ? * *")
    public void updateViewCount(){
        System.out.println("定时任务执行了");
        LocalDate now = LocalDate.now();
        LocalDate begin = LocalDate.of(2020, 7, 8);
        long betweenDays = ChronoUnit.DAYS.between(begin, now);
        Date date = new Date();
        DateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
        String today =df.format(date);
//        Long userId= 2940839987L;
        Long userId= Long.valueOf(userQQ);
        String message;
        /*message= "【"+today+"】[CQ:face,id=214]"+"\n帆帆宝贝小达向您请安![CQ:face,id=74]\n"+"我们在一起已经"+betweenDays+"天啦![CQ:face,id=53]\n"
                +"我想对你说：[CQ:face,id=86]\n"+LoverWordUtil.getLoverWord()+"\n"+"【武冈天气】：\n"+ WeatherUtil.getWeather("武冈");*/
        message= "【"+today+"】[CQ:face,id=214]"+"\n帆帆宝贝小达向您请安![CQ:face,id=74]\n"+"我们在一起已经"+betweenDays+"天啦![CQ:face,id=53]\n"
                +"我想对你说：[CQ:face,id=86]\n"+LoverWordUtil.getLoverWord()+"\n";
        message = URLEncoder.encode(message, StandardCharsets.UTF_8);
        String url = "http://127.0.0.1:5700/send_private_msg?user_id="+userId+"&message="+message;
        HttpRequestUtil.doGet(url);
    }
}